package com.silences.servlet;

import com.alibaba.fastjson.JSON;
import com.silences.service.GoodsService;
//import com.silences.service.UserService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.rmi.ServerException;
import java.sql.SQLException;
import java.util.Map;


@WebServlet("/deleteGoods") //设置接口路径
public class DeleteGoodsServlet extends HttpServlet {
    //extends 继承 HttpServlet类

    //get 请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp){

    }


    //post 请求
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServerException,IOException {

        //post 请求优点  1 接收的数据量比较大  2 数据相对安全的

        //获取前端传递参数
        String id =req.getParameter("goodsnum");

        GoodsService userService=new GoodsService();



        try {
            Map<String,Object> map = userService.deleteGoods(Integer.parseInt(id));
            //返回数据给前端

            resp.getWriter().write(JSON.toJSON(map).toString());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
